/**
 * Created by Administrator on 2017/2/27 0027.
 */
function JsonOBJ() {
    this.id = null;
    this.majorname = null;
    this.classname = null;
    this.studentname = null;
    this.startTime = null;
    this.endTime = null;
    this.teachername = null;
    this.requestReason = null;
    this.rejectReason = null;
    this.authStatus = null;
    this.requestTime = null;
}

$(function () {
    $(".feedback").click(function () {
        var checked = (sessionStorage.getItem("checked")).split(',');
        if (checked == null || checked.length == 0) {
            layer.msg("请开启本地存储", {time: 1000});
            return;
        }
        if ($("#apply-not-reason").val() == "") {
            layer.msg("拒绝原因不能为空", {time: 1000});
            return;
        }
        approveList(1, checked);
    });
});


function approveList(type, checked) {
    var checkIds = new Array();

    for (var i = 0; i < checked.length; i++) {
        var js = new JsonOBJ();
        js.id = checked[i];
        if (type == 0) {
            js.authStatus = 1;
            js.rejectReason = "";
        } else {
            js.authStatus = 2;
            js.rejectReason = $("#apply-not-reason").val();
        }
        checkIds.push(js);
    }
    $.ajax({
        url: "/huaqiao/front/teacher/approve?" + new Date().getTime(),
        type: "post",
        data: JSON.stringify(checkIds),
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        async: false,
        success: function (str) {
            if (check(str)) {
                if (str == checkIds.length) {
                    layer.msg("批准成功", {time: 1000});
                    pageNo = 1;
                    setTimeout(function () {
                        window.location = 'apply.weApprove_teacher.html';
                    }, 1000);
                } else {
                    layer.msg("失败" + (checkIds.length - parseInt(str)) + "条！", {time: 1000});
                    pageNo = 1;
                    setTimeout(function () {
                        window.location = 'apply.weApprove_teacher.html';
                    }, 1000);
                }
            }
        }
    });
}

function check(str) {
    if (str != null && str != "" || str == 0) {
        if (str.errorcode != undefined) {
            if (str.errorcode == 1) {
                if (islogin == 1) {
                    layer.msg(str.errormessage, {time: 1000});
                    window.location.href = "/huaqiao/front_end/pc/teacher/login_pc_teacher.html";
                    islogin = 0;
                }
            }
            return false;
        } else {
            return true;
        }
    } else {
        return false;
    }
}